<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String newsId = request.getParameter("newsId");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>详细帖子页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<%=basePath%>JS/jquery-ui-1.11.2/external/jquery/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>JS/jquery-ui-1.11.2/jquery-ui.js"></script>
	<script type="text/javascript" src="<%=basePath%>JS/jquery-validation-1.13.1/dist/jquery.validate.js"></script>
	<link rel="stylesheet" type="text/css" href="<%=basePath%>JS/jquery-ui-1.11.2/jquery-ui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>JS/jquery-validation-1.13.1/demo/css/screen.css">
  </head>
  
  <body>
     <div id="head-search">
   	 		<span class="home-path"></span>
   	 		<span class="path-font">学习交流管理&nbsp;&nbsp;>>&nbsp;&nbsp;新鲜事管理&nbsp;&nbsp;>>&nbsp;&nbsp;帖子详情 </span>
   		</div>
   		<div class="mainbody">
   			<div id="mynewsdetail" class="divblock">
   				<div id="newstheme"></div>
   				<div  class="newstitle" ><span class="span" id="releaser"></span><span class="span" id="newsdate"></span></div>
   				<div id="newscontent" class="divrow"></div>
   			</div>	
   			<div class="" >
   					<span class="span"><button>赞</button></span>
   					<span class="span"><button id="commentbtn">评论</button></span>
   					<div class="divrow" id="commenttext">
   						<textarea id="commenttextarea" rows="5" cols="60"></textarea>
   						<button id="saveComBtn" class="wong-button-text-ui wong-button-blue">
   							<span class="wong-ui-icon wong-icon-save"></span>
   							<span >发表评论</span>
   						</button>
   				    </div>
   			</div>
   			<div class="divblock" id="allcommentarea">
   			</div>
   			
   		</div>
   
  </body>
  <script type="text/javascript">
  		$(function(){
  			var commenttextIsShow = false;
  			$("#commenttext").hide();
  			var newsId = "<%=newsId%>";
  
  			//请求获取帖子详细信息
  		  		$.ajax({
  		  			url:'<%=basePath%>getNewsDetailAction',
  		  			type:'get',
  		  			typeData:'json',
  		  			data:{'newsId':newsId},
  		  			timeout:1000,
  		  			beforeSend:beforeFunc,
  		  			error:errorFunc,
  		  			success:sucFunc,				
  		  		});
  				//加载当前帖子的所有评论
  				loadAllComment(newsId);
  		  		function beforeFunc(){}
  		  		function errorFunc(){}
  		  		//成功获取帖子信息后处理函数
  		  		function sucFunc(datas){
  		  			var json = eval("("+datas+")");
  		  			getMemberDetail(json.newsReleaser,document.getElementById("releaser"));
  		  			$("#newstheme").html(json.newsTheme);
  		  			$("#newsdate").html("&nbsp;发布于： "+json.newsDate);
  		  			$("#newscontent").html(json.newsContent);
  		  		}
  		  		//获取个人基本信息
  		  		function getMemberDetail(memId,element){
  		  		$.ajax({
  		  			url:'<%=basePath%>memberAction',
  		  			type:'get',
  		  			typeData:'json',
  		  			data:{'memID':memId},
  		  			timeout:1000,
  		  			beforeSend:beforeFunc,
  		  			error:errorFunc,
  		  			success:function(datas){
  		  				var json = eval("("+datas+")");
  		  				//$("#releaser").html("<a href='<%=basePath%>/user/member.jsp?memId="+json[0].memId+"'>"+json[0].memname+"</a>");
  		  				element.innerHTML="<a href='<%=basePath%>/user/member.jsp?memId="+json[0].memId+"'>"+json[0].memname+"</a>";
  		  			},				
  		  		});
  		  		}
  		  		
  		  		//评论Button函数
  		  		$("#commentbtn").click(function(){
  		  			if(!commenttextIsShow){
  		  				$("#commenttext").show();
  		  			    $("#commentbtn").text("收起评论");
  		  			    $("#commenttextarea").focus();
  		  				commenttextIsShow = true;
  		  			}else{
  		  				$("#commenttext").hide();
  		  				 $("#commentbtn").text("评论");
  		  				commenttextIsShow = false;
  		  			}
  		  		});
  		  		//发表评论按钮
  		  		$("#saveComBtn").click(function(){
  		  			$.ajax({
  		  				url:'<%=basePath%>relCommentAction',
  		  				type:'post',
  		  				typeData:'json',
  		  				timeout:1000,
  		  				data:{'newsId':newsId,'comContent':$("#commenttextarea").val()},
  		  				beforeSend:beforeFunc,
  		  				error:errorFunc,
  		  				success:function(){
  		  					$("#commenttextarea").val("");
  		  					alert("发表成功");
  		  					$("#commenttext").hide();
  		  				 	$("#commentbtn").text("评论");
  		  					commenttextIsShow = false;
  		  					loadAllComment(newsId);
  		  					}
  		  			});
  		  		});
  		  		
  		  		//加载请求当前帖子的评论
  		  		function loadAllComment(newsId){
  		  			$.ajax({
  		  			url:'<%=basePath%>getAllCommentAction',
  		  			type:'get',
  		  			typeData:'json',
  		  			data:{'newsId':newsId},
  		  			timeout:1000,
  		  			beforeSend:beforeFunc,
  		  			error:errorFunc,
  		  			success:afterLoadComment	
  		  			});
  		  		}
  		  		
  		  	
  		  		//加载所有评论完成后的处理函数,显示评论
  		  		function afterLoadComment(datas){
  		  			var json = eval("("+datas+")");
  		  			$("#allcommentarea").html("");
  		  			$.each(json,function(index){
  		  			var	commentId=json[index].commentId,
  		  		 		newsId=json[index].newsId,
  		  		 		commentater=json[index].commentater,
  		  		 		commentDate=json[index].commentDate,
  		  				commentContent=json[index].commentContent,
  		  		 		floor=json[index].floor,
  		  				good=json[index].good;
  		  				$("#allcommentarea").html($("#allcommentarea").html()+
  		  						"<div class='commentlistclass'><div class='divrow'><span class='commentater'>"+commentater+
  		  						"</span><span class='span'>发表于：</span>"+
  		  						"<span class='span'>"+commentDate+"</span><span class='span' style='float:right;'>"+floor+"&nbsp;楼</span></div>"+
  		  						"<div class='divrow'>"+commentContent+
  		  						"</div></div>");
  		  			});
  		  			
  		  			var documents = document.getElementsByClassName("commentater");
  		  			for (var i=0; i<documents.length; i++) {
  		  					//alert(documents[i].innerHTML);
  		  				getMemberDetail(documents[i].innerHTML,documents[i]);
  		  			}
  		  		}
  		  		
  		  		
  		  		
  		});
  </script>
</html>
